\I[Make your own Chunky 2 Planar|By Scout|Section: Graphicians & Coders Pool]
\F2\4\MMake yor own C2P
\F3\2
\C[ClipArts/pinnen.Chnk]
The basic idea of Chunky-to-Planar conversion is to convert one chunky-pixel (one byte containing the complete color value of one pixel) to bitplane-data. This is achieved by writing one bit of the chunky-pixel to each bitplane. That way, one can have a putpixel-routine that does all the work. However, the conversion is extremely slow. It does, for instance, write the same byte eight (!) times when drawing horizontal lines (one write (or rather 'or.b') per bit to be set). Isn't there any other way?
Yes there is. If one would have a temporary buffer where one would draw the chunky-pixels (not converting them in any way), and a C2P-routine then would convert the whole buffer into bitplanes (writing data directly to the screen), there would be a tremendous speed-increase since the C2P-routine can deal with many pixels at once!
The simplest (and slowest) C2P-routine grabs 8 pixels at a time. The more complex ones handle 16 pixels (or 32, but they then need a temporary buffer). The C2P conversion is handled through a magic process.
\C[ClipArts/pinnen.Chnk]
\3Knowledge of a few special operations are required:
Rotation (90 degrees counterclockwise):
This has the following effect:
(Each letter represents a bit in the byte)
abcdefgh
ijklmnop
Rot 1x1
bjdlfnhp
aickemgo
The data is split up into 2x2 segments. Inside each segment, a 1x1 rotation is performed: a moves down, b moves left, i moves right, j moves up.
A 2x2 rotation means that the data is split up into 4x4 segments, and inside each segment 2x2 blocks (instead of single pixels) are moved. The order inside each 2x2 block shouldn't be changed.
It is done like this:
abcd
efgh
ijkl
mnop
Rot 2x2
cdkl
ghop
abij
efmn
A 1x1 swap is performed like this:
; d0 and d1 contains bit pattern
; Bit mask with every 2nd bit set
move.b #$55,d7
move.b d0,d2
; Mask out the bits changing byte
and.b d7,d0
; Mask out the other ones in d2
eor.b d0,d2
; Do the left-move
lsl.b #1,d0
move.b 1,d3
; Mask out the bits not changing byte
and.b d7,d3
; Mask out the other ones in d2
eor.b d3,d1
; Do the right-move
lsr.b #1,d0
; Do the up-move
or.b d3,d0
; Do the down-move
or.b d2,d1
Swap:
This one is almost exactly like the rotation. It exchanges bits diagonally: